TailsConfig.registerFormat({
  name: 'geo',
  topNodeClass: 'geo',

  customBindings: {
    geo: function(node, object) {
      if (node.tagName.toLowerCase() == 'abbr') {
        var s = FormatBase.toText(node);
        if (s.match(/^\s*([0-9\.-]+)\s*[;,]\s*([0-9\.-]+)\s*$/)) {
          object.latitude = RegExp.$1;
          object.longitude = RegExp.$2;
          if (node.tagName.toLowerCase() == 'abbr')
            object.label = FormatBase.evalTextNode(node);
        }
      }
    },
    latitude: function(node, object) {
      object.latitude = FormatBase.toText(node);
      if (node.tagName.toLowerCase() == 'abbr')
        object.latitude_label = FormatBase.evalTextNode(node);
    },
    longitude: function(node, object) {
      object.longitude = FormatBase.toText(node);
      if (node.tagName.toLowerCase() == 'abbr')
        object.longitude_label = FormatBase.evalTextNode(node);
    }
  },

  _getLabel: function(object) {
    if (object.latitude_label) {
      return object.latitude_label + ' ' + object.longitude_label;
    } else if (object.latitude) {
      var s = object.latitude + ', ' + object.longitude;
      if (object.label)
        s += " (" + object.label + ")";
      return s;
    }
  },

  end: null
});
